<template>
	<view>
		<view class="box" v-if="determine">
			<view class="first">
				<view class="firstText1">请上传本人身份证照</view>
				<view class="firstText2">为有效保障您的使用体验，提高订单审核效率，请填写与您身份证一致的信息，否则不会审核通过。</view>
				<view class="firstText3">
					<view class="text3Box" @click="onUploadImage('idcardBadUrl')">
						<image :src="imageForm.idcardBadUrl || '../../static/name1.png'" class="text3Img" />
						<view class="textView">上传身份证人像面</view>
						<view class="reset_text" v-show="imageForm.idcardBadUrl">重新上传</view>
					</view>
					<view class="text3Box" @click="onUploadImage('idcardFrontUrl')">
						<image :src="imageForm.idcardFrontUrl || '../../static/name2.png'" class="text3Img" />
						<view class="textView">上传身份证国徽面</view>
						<view class="reset_text" v-show="imageForm.idcardFrontUrl">重新上传</view>
					</view>
				</view>
			</view>
			<view class="first">
				<view class="firstText1">拍摄身份证规范要求</view>
				<view class="firstText2">
					大陆公民持有的本人有效二代身份证，拍摄时确保身份证<text style="color: red;">边框完整、字体清晰、亮度均匀。</text>
				</view>
				<view class="firstText3">
					<view class="text3Box">
						<image src="../../static/name3.png" class="text3Img2" />
						<view class="textView">正确示范</view>
					</view>
					<view class="text3Box">
						<image src="../../static/name4.png" class="text3Img2" />
						<view class="textView">曝光强烈</view>
					</view>
					<view class="text3Box">
						<image src="../../static/name5.png" class="text3Img2" />
						<view class="textView">边框缺失</view>
					</view>
					<view class="text3Box">
						<image src="../../static/name6.png" class="text3Img2" />
						<view class="textView">照片模糊</view>
					</view>
				</view>
			</view>
			<view class="buttonBox">
				<button class="button" @click="onSubmit">确定提交</button>
			</view>
		</view>
		<view v-else class="box">
			<view class="first">
				<view class="firstText1">本人身份证照</view>
				<view class="firstText3">
					<view class="text3Box">
						<image src="../../static/name1.png" class="text3Img" />
						<view class="textView">上传身份证人像面</view>
					</view>
					<view class="text3Box">
						<image src="../../static/name2.png" class="text3Img" />
						<view class="textView">上传身份证国徽面</view>
					</view>
				</view>
			</view>
			<view class="first">
				<view class="firstText1">实名信息</view>
				<view class="firstText4">
					<view class="Text4View1">姓名</view>
					<view class="Text4View2">张欣蕊</view>
				</view>
				<view class="firstText4">
					<view class="Text4View1">性别</view>
					<view class="Text4View2">女</view>
				</view>
				<view class="firstText4">
					<view class="Text4View1">年龄</view>
					<view class="Text4View2">24</view>
				</view>
				<view class="firstText4">
					<view class="Text4View1">身份证号</view>
					<view class="Text4View2">678912898918923</view>
				</view>
				<view class="firstText4">
					<view class="Text4View1">出生年月</view>
					<view class="Text4View2">2002-04-13</view>
				</view>
				<view class="firstText4">
					<view class="Text4View1">户籍住址</view>
					<view class="Text4View2">浙江省杭州市西湖区XXXXX小区</view>
				</view>
				<view class="firstText4">
					<view class="Text4View1">有效期至</view>
					<view class="Text4View2">2023-10-13至2033-10-12</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import permision from "@/js_sdk/wa-permission/permission.js"
	import uniSegmentedControl from "@/components/uni-segmented-control/uni-segmented-control.vue"
	import {
		submitIdCardImage
	} from '../../api/common'
	import {
		getUserInfo
	} from '../../api/login';
	import {
		uploadImageOne
	} from '../../utils/request'
	export default {
		components: {
			uniSegmentedControl
		},
		onLoad(option) {},
		data() {
			return {
				determine: true,
				imageForm: {
					idcardBadUrl: '',
					idcardFrontUrl: '',
				},
				userInfo: null,
				isIos: true,
				items: ['iOS', 'Android']
			}
		},
		onReady() {
			this.getUserDetail();
		},
		onLoad() {
			// #ifdef APP-PLUS
			this.isIos = (plus.os.name == "iOS")
			// #endif
		},
		methods: {
			judgeIosPermission: function(permisionID) {
				var result = permision.judgeIosPermission(permisionID)
				console.log(result);
				var strStatus = (result) ? "已" : "未"
				uni.showModal({
					content: permisionID + '权限' + strStatus + "获得授权",
					showCancel: false
				});
			},
			async requestAndroidPermission(permisionID) {
				var result = await permision.requestAndroidPermission(permisionID)
				var strStatus
				if (result == 1) {
					strStatus = "已获得授权"
				} else if (result == 0) {
					strStatus = "未获得授权"
					uni.showModal({
						content: permisionID + strStatus,
						showCancel: false
					});
				} else {
					strStatus = "被永久拒绝权限"
				}

			},
			gotoAppPermissionSetting: function() {
				permision.gotoAppPermissionSetting()
			},
			checkSystemLocationStatus: function() {
				// var result = permision.checkSystemEnableLocation()
				// console.log(result);
				uni.showModal({
					content: '本机的位置服务开启状态：' + permision.checkSystemEnableLocation(),
					showCancel: false
				});
			},
			gotoAndroidPermissionSetting: function() {
				var main = plus.android.runtimeMainActivity(); //获取activity  
				var Intent = plus.android.importClass('android.content.Intent');
				var Settings = plus.android.importClass('android.provider.Settings');
				var intent = new Intent(Settings
				.ACTION_WIRELESS_SETTINGS); //可设置http://ask.dcloud.net.cn/question/14732这里所有Action字段
				main.startActivity(intent);
			},
			async onSubmit() {
				const {
					idcardBadUrl,
					idcardFrontUrl
				} = this.imageForm;
				if (!idcardBadUrl) return uni.showToast({
					title: '请上传身份证人像面',
					icon: 'none'
				});
				if (!idcardFrontUrl) return uni.showToast({
					title: '请上传身份证国徽面',
					icon: 'none'
				});
				await submitIdCardImage(this.imageForm).then(res => {
					uni.showToast({
						title: '提交成功',
						icon: 'none'
					});
					setTimeout(() => {
						uni.navigateBack()
					}, 1500)
				}).catch(err => {
					uni.showToast({
						title: err,
						icon: "none"
					})
				})
			},
			getUserDetail() {
				getUserInfo().then(({
					data
				}) => {
					this.userInfo = data;
					if (data.clientUser.idcardBadUrl && data.clientUser.idcardFrontUrl) {
						this.determine = false;
					} else {
						this.determine = true;
					}
				})
			},
			onUploadImage(field) {
				console.log("进入测试")
				// if (!this.isIos) {
				// 	this.requestAndroidPermission('android.permission.READ_EXTERNAL_STORAGE')
				// }
				let that = this;
				uni.showActionSheet({
					itemList:['拍摄','从相册选择'],
					success(res){
						console.log(res)
						if(res.tapIndex==0){
							uploadImageOne({
								url:'wx/common/upload',
								sourceType : ['camera'],
							}, (res) => {
								that.imageForm[field] = res.url;
							})
							// uni.showModal({
							// 	title: '上传身份证需要下列权限才可以正常使用',
							// 	content: '摄像头权限(拍摄身份证照片)',
							// 	success: function(res) {
							// 		if (res.confirm) {
							// 			uploadImageOne({
							// 				url:'wx/common/upload',
							// 				sourceType : ['camera'],
							// 			}, (res) => {
							// 				that.imageForm[field] = res.url;
							// 			})
							// 		}
							// 	}
							// });
						}else{
							uploadImageOne({
								url:'wx/common/upload',
								sourceType : ['album'],
							}, (res) => {
								that.imageForm[field] = res.url;
							})
							// uni.showModal({
							// 	title: '上传身份证需要下列权限才可以正常使用',
							// 	content: '存储权限(读取相册身份证照片)',
							// 	success: function(res) {
							// 		if (res.confirm) {
							// 			uploadImageOne({
							// 				url:'wx/common/upload',
							// 				sourceType : ['album'],
							// 			}, (res) => {
							// 				that.imageForm[field] = res.url;
							// 			})
							// 		}
							// 	}
							// });
						}
					}
				})
				
				// uni.showModal({
				// 	title: '上传身份证需要下列权限才可以正常使用',
				// 	content: '和摄像头权限(拍摄身份证照片)',
				// 	success: function(res) {
				// 		if (res.confirm) {
							
				// 		}
				// 	}
				// });
				
				

			},
		}
	}
</script>

<style lang="less" scoped>
	page {
		background: #F5F7FA;
	}

	@import './index.less';
</style>